import os

total=23
a=7
b=12

bt_list = list(range(1, 17))
bt_list += list(range(20, 129, 4))

for exe in os.listdir('..'):
    # if '2d' in exe:
    if '2d-gaussian' in exe:
        print(exe)
        os.system(f'rm  -f result/1024-{exe}.log')

        f = open(f'result/1024-{exe}.log', 'w')

        for n in range(a, b + 1):
            last_bx_perf = -1
            bx_dec_cnt = 0
            if n != 10:
                continue
            for log_bx in [6, 7, 8, 9]:
                bx_perfs = []
                last_perf = -1
                dec_cnt = 0
                for bt in bt_list:
                    N, T, BX, BT = 2**n, 2**(total - a - (n - a) * 2), 2**log_bx, bt
                    BY = 2 * BX
                    # print(f'../{exe}/exe-{exe} {N} {T} {BX} {BX} {BT}')
                    print(f'N = {N}, T = {T}, BX = {BX}, BY = {BY}, BT = {BT}, ', end='')
                    output = os.popen(f'../{exe}/exe-{exe} {N} {N} {T} {BX} {BY} {BT}').read()
                    f.write(f'NX = {N}, NY = {N}, T = {T}, BX = {BX}, BY = {BY}, BT = {BT}, ')
                    if '\n' not in output:
                        f.write('\n')
                        break
                    else:
                        f.write(output)
                        print(output.strip())
                        perf = output.strip().split(' = ')[-1]
                        if 'inf' in perf or float(perf) > 1000: 
                            break

                        perf = float(perf)
                        bx_perfs.append(perf)
                        if perf < last_perf:
                            dec_cnt += 1
                        else:
                            dec_cnt = max(0, dec_cnt - 1)
                        last_perf = perf
                        # if dec_cnt >= 3:
                        #     break
                if len(bx_perfs) == 0:
                    continue
                cur_bx_perf = max(bx_perfs)
                if cur_bx_perf < last_bx_perf:
                    bx_dec_cnt += 1
                else:
                    bx_dec_cnt = max(0, bx_dec_cnt - 1)
                last_bx_perf = cur_bx_perf
                # if bx_dec_cnt >= 3:
                #     break

                f.flush()
        f.close()
